<?php
class dao_comercios
{
	function get_listado_comercios($where=null)
	{
		$sql = '';
		if (isset($where)) {
			$sql = "SELECT id_comercio, comercio, razon_social, cuit, inicio_act, direccion, 
					id_localidad, telefono, email, web, contacto_comercial, cargo, 
					dni, direccion_contacto, tel_contacto, cel_contacto, email_contacto
					FROM comercios
					where $where";
		} else {
			$sql = "SELECT id_comercio, comercio, razon_social, cuit, inicio_act, direccion, 
					id_localidad, telefono, email, web, contacto_comercial, cargo, 
					dni, direccion_contacto, tel_contacto, cel_contacto, email_contacto
					FROM comercios";
		}
		return consultar_fuente($sql);
	}
	
	static function get_comercios($filtro=null, $locale=null)
    {
          if (! isset($filtro) || trim($filtro) == '') {
              return array();
          }
          $where = '';
          if (isset($locale)) {
              $locale = quote($locale);
              $where = "AND locale=$locale";
          }
          $filtro = quote("{$filtro}%");
          $sql = "SELECT 
                        id_comercio,(comercio||', '||razon_social)
						AS comercio FROM comercios
                  WHERE
                      comercio ILIKE $filtro 
          ";
          return consultar_fuente($sql);        
      }      
	  
      static function get_comercio_combo($id=null)
      {
          if (! isset($id)) {
              return array();
          }
          $id = quote($id);
          $sql = "SELECT
						id_comercio,(comercio||', '||razon_social)
						AS comercio FROM comercios
			      WHERE 
						comercios.id_comercio=$id";
          $result = consultar_fuente($sql);    
         if (! empty($result)) {
              return $result[0]['comercio'];
          }
      }    
	
}
?>